package com.inetools.gwt.gajaxs.client;

import com.google.gwt.core.client.JavaScriptObject;

/**
 * Interface for providing services for callback at callbacked side
 * @author ay
 *
 */
public interface Callbackee {
	/**
	 * @return request URL what name of method being callbacked will be appended at end of. 
	 */
	public String getRequestUrlForCallback();
	
	/**
	 * @return Prefix of callback name.
	 */
	public String getCallbackBaseName();
	/**
	 * @return Id to identify callback. Becomes a part of suffix of callback name.
	 */
	public int getCallbackId();
	/**
	 * @return Becomes a part of suffix of callback name. Used to identify specific attempt of callback.
	 * When this returns null, setTimeStamp will be called to initialize.
	 */
	public String getCallbackTimeStamp();
	/**
	 * Used to initialize or update time stamp which is used as signature for specific attempt of callback.
	 * @param timeStamp
	 */
	public void setCallbackTimeStamp( String timeStamp);
	/**
	 * @return Maximum count to send request for callback
	 */
	public int getCallbackMaxCount();
	/**
	 * Called when callback does not happen even after maximum count of attempt.
	 */
	public void fireCallbackFailureEvent();
	/**
	 * Called when callback succeeds.
	 * @param jsObj: Data passed by from callbacked server 
	 */
	public void fireCallbackEvent( JavaScriptObject jsObj);
	
	/**
	 * @return milliseconds time out to cancel callback after sending request 
	 */
	public int getCallbackRequestTimeOut();
	
	/**
	 * Called after time out period. 
	 * In implementation, wrap the method (which sends request for call back) within this method. 
	 * Otherwise, re-attempt of sending request for callback will never happen when timeout occurs.  
	 */
	public void postCallbackRequestTimeout();
	
	/**
	 * @param jsTimeoutObjReferrer: Javascript's Timeout object's ID
	 */
	public void setJsTimeoutObjReferrerForCallback( int jsTimeoutObjReferrer);
	
	/**
	 * To notify to listeners that request has been sent to server 
	 */
	public void dispatchRequestSentNotice();
}
